﻿/// <reference path="../../Core.ts" />

module Supernova {

    export class ResearchCategoryPanel {

        layout = {
            researchCategoryPanel: {
                left: 140, top: 10, width: 200, bottom: 10,
                visible: false,
                controls: {
                    researchFacilityButton: {
                        top: 0, height: 30,
                        text: 'Facilities',
                        helpText: 'Unlocks specific buildings that you can create on occupied planets.',
                        onClick: this.handleFacilityButtonClicked,
                        onEnter: this.handleResearchButtonEnter
                    },
                    researchShipDesignButton: {
                        top: 40, height: 30,
                        text: 'Ship Design',
                        helpText: 'Unlocks slots in the ship construction interface allowing for more powerful ships.',
                        onClick: this.handleShipButtonClicked,
                        onEnter: this.handleResearchButtonEnter
                    },
                    researchActionButton: {
                        top: 80, height: 30,
                        text: 'Actions',
                        helpText: 'Unlocks new actions that can be performed in the game.',
                        onClick: this.handleActionButtonClicked,
                        onEnter: this.handleResearchButtonEnter
                    },
                    researchPassiveButton: {
                        top: 120, height: 30,
                        text: 'Passive',
                        helpText: 'Enables effects that take place passively in the game.',
                        onClick: this.handlePassiveButtonClicked,
                        onEnter: this.handleResearchButtonEnter
                    }
                }
            }
        }

        public parent: GameUI = null;

        public root: UI.UIControl = null;

        constructor(parent: GameUI) {
            this.parent = parent;
            this.root = UI.compile(this.layout)[0];
        }

        public indicateAvailability() {
            UI.getControlByName(gameUI.root, 'researchFacilityButton').enabled = gameUI.researchFacilityPanel.controls.length > 0;
            UI.getControlByName(gameUI.root, 'researchShipDesignButton').enabled = gameUI.researchShipPanel.controls.length > 0;
            UI.getControlByName(gameUI.root, 'researchActionButton').enabled = gameUI.researchActionPanel.controls.length > 0;
            UI.getControlByName(gameUI.root, 'researchPassiveButton').enabled = gameUI.researchPassivePanel.controls.length > 0;
        }
        
        handleResearchButtonEnter(sender, e) {
            if (!sender.enabled) return;
            toolTipCanvas = ToolTip.render([{ type: 'title', text: sender.text }, { type: 'text', text: sender.helpText }]);
        }

        handleShipButtonClicked(sender, e) {
            var visible = !gameUI.researchShipPanel.visible;
            gameUI.hidePanels();
            gameUI.researchCategoryPanel.root.visible = true;
            gameUI.researchShipPanel.visible = visible;
        }

        handleFacilityButtonClicked(sender, e) {
            var visible = !gameUI.researchFacilityPanel.visible;
            gameUI.hidePanels();
            gameUI.researchCategoryPanel.root.visible = true;
            gameUI.researchFacilityPanel.visible = visible;
        }

        handleActionButtonClicked(sender, e) {
            var visible = !gameUI.researchActionPanel.visible;
            gameUI.hidePanels();
            gameUI.researchCategoryPanel.root.visible = true;
            gameUI.researchActionPanel.visible = visible;
        }

        handlePassiveButtonClicked(sender, e) {
            var visible = !gameUI.researchPassivePanel.visible;
            gameUI.hidePanels();
            gameUI.researchCategoryPanel.root.visible = true;
            gameUI.researchPassivePanel.visible = visible;
        }

    }

}